#ifndef FILEHELPER_H
#define FILEHELPER_H

#include <QDIr>
#include <QFile>
#include <QString>
#include <QMessageBox>
#include <QTextStream>
#include <QTranslator>
#include <QUrl>
#include <QFileDialog>
#include <QDebug>

/**
 * @brief Some operations about file and folder
 */

class FileHelper : public QObject
{
public:
    FileHelper();
    bool CreateFolder(QString folderName,QString path);
    bool CreateFile(QString fileName,QString path);
    bool AppendText(QString path, QString strContent )
    {
        QFile inFile(path);
        if (!inFile.open(QIODevice::Append | QIODevice::Text))
        {
            QMessageBox::information(NULL,tr("Warning"),tr("Error opening the file!"));
            return false;
        }
        QTextStream inStream(&inFile);
        inStream<<strContent;
        inFile.close();
        return true;
    }

    QList<QString> ReadFile(QString path)
    {
        QList<QString> urls;
        QFile file(path);
        if(!file.exists())
        {
            file.open(QFile::WriteOnly);
            file.close();
        }
        if(file.open(QFile::ReadOnly))
        {
            QDataStream in(&file);
            in >> urls;
            file.close();
        }
        else
        {
            QMessageBox::warning(0,
                                 "Error",
                                 "Unable to load file!",
                                 QMessageBox::Ok);
        }
    }

    QString FileOpenPicker()
    {
        QString dir = QFileDialog::getExistingDirectory(0,"Save Folder","\home");
        qDebug()<<dir;
    }

};

#endif // FILEHELPER_H
